package condominio.servlet.vivenda;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import condominio.excepcion.DAOExcepcion;
import condominio.modelo.Vivienda;
import condominio.negocio.condominioNegocio;

/**
 * Servlet implementation class RegistraViviendaServlet
 */
@WebServlet("/RegistraViviendaServlet")
public class RegistraViviendaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistraViviendaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String a = request.getParameter("area");
		String b = request.getParameter("tipo");
		String c = request.getParameter("edificio");
		String d = request.getParameter("zona");
		String e1 = request.getParameter("numero");
		String f = request.getParameter("idprop");
		String g = request.getParameter("idres");
		String h = request.getParameter("idadmin");
		String k = request.getParameter("estado");
		

		Vivienda vi = new Vivienda();
		vi.setArea(a);
		vi.setTipo(b);
		vi.setEdificio(c);
		vi.setZona(d);
		vi.setNumero(e1);
		vi.setPropietario(f);
		vi.setResidente(g);
		vi.setAdmin(h);
		vi.setEstado(k);
	
		condominioNegocio negocio = new condominioNegocio();
		try {
			negocio.registrarVivienda(vi);
			response.sendRedirect(request.getContextPath() + "/RegistraViviendaServlet");
		
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		
		
		
	}

}
